<template>
    <div class="schedulingMain">
      <div class="content">
        <div class="content_top">
          <div class="ct_first">
            <span class="title">生产排程</span>
            <span class="setting" @click="toSetParam">参数设置</span>
          </div>
          <div class="ct_second">
            <!-- 订单编号 -->
            <div class="cts_con">
              <div class="ctsc_title">订单编号</div>
              <div class="ctsc_inputs">
                <i class="el-icon-caret-bottom icon"></i>
                <el-select v-model="order_num" placeholder="请选择">
                  <el-option
                    v-for="item in order_list.order"
                    :key="item"
                    :label="item"
                    :value="item">
                  </el-option>
                </el-select>
              </div>
            </div>
            <!-- 时间 -->
            <div class="cts_con">
              <div class="ctsc_title">时间</div>
              <div class="ctsc_inputs">
                <i class="el-icon-caret-bottom icon"></i>
                <el-date-picker
                  v-model="time"
                  :clearable="false"
                  type="date"
                  @change="changeTime"
                  placeholder="选择日期">
                </el-date-picker>
              </div>
            </div>
          </div>
        </div>
        <div class="content_bottom" v-if="schedule_detail.flow != undefined">
          <div class="cb_left">
            <!-- 第一个 -->
            <div class="cbl_one" id="cb1" v-for="(i,index) in schedule_detail.flow.node" v-if="i.edi != undefined" :key="index">
              <div class="cblCon_top">
                <div class="cbt_title">{{i.edi.name}}</div>
                <span class="status">当前状态</span>
                <span class="downStatus" :class="[{'cg':i.edi.status=='处理完成'},{'cl':i.edi.status=='等待确认'},{'error':i.edi.status=='处理错误'},{'wait':i.edi.status=='等待处理'}]">{{i.edi.status}}</span>
                <span class="time" v-if="i.edi.time != 0">上次处理时间：{{i.edi.time | changeDateTime}}</span>
              </div>
              <div class="cblCon_bottom cb1"></div>
            </div>
            <!-- 第二个 -->
            <div class="cbl_one" id="cb2" v-for="(i,index) in schedule_detail.flow.node" v-if="i.res!=undefined" :key="index">
              <div class="cblCon_top" @click="toAutoMatic">
                <div class="cbt_title">{{i.res.name}}</div>
                <span class="status">当前状态</span>
                <span class="downStatus" :class="[{'cg':i.res.status=='处理完成'},{'cl':i.res.status=='等待确认'},{'error':i.res.status=='处理错误'},{'wait':i.res.status=='等待处理'}]">{{i.res.status}}</span>
                <span class="time" v-if="i.res.time != 0">上次处理时间：{{i.res.time | changeDateTime}}</span>
              </div>
              <div class="cblCon_bottom" @click="csvClick(1)">
                <div class="cblb_con">导出排产结果</div>
              </div>
            </div>
          </div>
          <div class="cb_right">
            <!-- 第三个 -->
            <div class="cbl_two" v-for="(i,index) in schedule_detail.flow.node" v-if="i.mes != undefined" :key="index">
              <div class="cblCon_top">
                <div class="cbt_title">{{i.mes.name}}</div>
                <span class="status">当前状态</span>
                <span class="downStatus" :class="[{'cg':i.mes.status=='处理完成'},{'cl':i.mes.status=='等待确认'},{'error':i.mes.status=='处理错误'},{'wait':i.mes.status=='等待处理'}]">{{i.mes.status}}</span>
                <span class="time" v-if="i.mes.time != 0">上次处理时间：{{i.mes.time | changeDateTime}}</span>
              </div>
              <div class="cblCon_bottom">
                <div class="cblb_con" @click="csvClick(2)">导出月物料计划</div>
                <div class="cblb_con" @click="csvClick(3)">导出周物料计划</div>
              </div>
            </div>
            <!-- 第四个 -->
            <div class="cbl_two" v-for="(i,index) in schedule_detail.flow.node" v-if="i.k3!=undefined" :key="index">
              <div class="cblCon_top">
                <div class="cbt_title">{{i.k3.name}}</div>
                <span class="status">当前状态</span>
                <span class="downStatus" :class="[{'cg':i.k3.status=='处理完成'},{'cl':i.k3.status=='等待确认'},{'error':i.k3.status=='处理错误'},{'wait':i.k3.status=='等待处理'}]">{{i.k3.status}}</span>
                <span class="time" v-if="i.k3.time != 0">上次处理时间：{{i.k3.time | changeDateTime}}</span>
              </div>
              <div class="cblCon_bottom cb1"></div>
            </div>
          </div>
        </div>
      </div>
    </div>
</template>

<script>
  import qs from 'qs'
  import {changeDateTime,changeNewTime} from '@/util/filter'
  export default {
    name: "scheduling",
    data() {
      return {
        order_list: [],
        order_num: '',
        time:'',
        time2:'',
        schedule_detail:'',
      }
    },
    filters:{
      "changeDateTime":changeDateTime,
      "changeNewTime":changeNewTime
    },
    created() {
      let self = this
      self.time = changeNewTime(new Date());
      self.getOrderNumber({time:Date.parse(new Date(this.time)) /1000})
    },
    mounted() {
    },
    methods: {
      //获取订单编号
      getOrderNumber(params){
        let self = this
        self.$http.get(self.conURL + 'pm/api/schedule/ordernum?' + qs.stringify(params)).then(res => {
          self.order_list = res.data
          let data = {}
          if (self.order_list.order.length > 0){
            if (self.order_list.order[0] != undefined && self.order_list.order[0] != ''){
              self.order_num = self.order_list.order[0]
              data={
                ordernum:self.order_list.order[0],
                time:params.time
              }
              this.getSchedule(data)
            }else {
              self.order_list = '';
              self.order_num = '';
            }
          }else {
            self.time2 = self.time;
            self.time = changeNewTime(new Date(self.order_list.time * 1000));
            self.getOrderNumber({time:self.order_list.time})
          }
        })
      },
      //选择时间
      changeTime(val){
        let self = this
        self.time2 = ''
        if(self.order_num==''){
          var ordernum=self.order_list[0];
        }else{
          var ordernum=self.order_num
        }
        self.time = changeNewTime(val);
        let time =Date.parse(new Date(self.time)) /1000
        self.getOrderNumber({time:Date.parse(new Date(self.time)) /1000})
        self.getSchedule({ordernum:ordernum,time:time});
      },
      //排产数据
      getSchedule(params){
        let self = this
        self.$http.get(self.conURL + 'pm/api/schedule?' + qs.stringify(params)).then(res => {
          self.schedule_detail = res.data
        })
      },
      //前往自动排产
      toAutoMatic(){
        let self = this
        let newTime = ''
        if (self.time2 != null && self.time2 != ''){
          newTime = self.time2
        } else {
          newTime = self.time
        }
        self.$router.push({
          path:'/index/automatic',
          query:{time:newTime}
        })
      },
      //前往参数设置
      toSetParam(){
        let self = this
        self.$router.push('/index/setParam')
      },
      //导出计划(下载报表)
      csvClick(index){
        let self = this
        let time = Date.parse(new Date(this.time)) /1000
        if (index == 1){ //导出排产结果
          window.location.href = 'http://120.26.113.44:7080/pm/file/schedule/day/csv?time=' + time
        } else if (index == 2){ //导出月物料计划
          window.location.href = 'http://120.26.113.44:7080/pm/file/schedule/month/csv?time=' + time
        } else if (index == 3){ //导出周物料计划
          window.location.href = 'http://120.26.113.44:7080/pm/file/schedule/week/csv?time=' + time
        }
      },
    }
  }
</script>

<style lang="less">
  .schedulingMain{
    width: 100%;
    padding: 43px 62px;
    box-sizing: border-box;
    .content{
      display: flex;
      flex-direction: column;
      .content_top{
        background: #fff;
        border-bottom: 1px solid #e5e5e5;
        padding: 0 40px;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        border: 1px solid #e5e5e5;
        border-top-left-radius: 5px;
        border-top-right-radius: 5px;
        .ct_first{
          display: flex;
          flex-direction: row;
          justify-content: space-between;
          height: 95px;
          line-height: 95px;
          .title{
            color: #333333;
            font-size: 24px;
          }
          .setting{
            color: #0f76c8;
            font-size: 14px;
            cursor: pointer;
          }
        }
        .ct_second{
          display: flex;
          flex-direction: row;
          .cts_con{
            display: flex;
            flex-direction: column;
            padding-bottom: 30px;
            .ctsc_title{
              font-size: 14px;
              color: #666666;
              margin-bottom: 10px;
            }
            .ctsc_inputs{
              position: relative;
              margin-right: 10px;
              .el-input__inner,.el-date-editor{
                background: #fff;
                height: 40px;
                width: 286px;
                color: #222222;
                font-size: 14px;
                cursor: pointer;
              }
              .el-select__caret{
                display: none;
              }
              .icon{
                position: absolute;
                right: 15px;
                top: 11px;
                z-index: 10;
                color: #aaaaaa;
              }
              .el-input__inner{
                padding-right: 30px;
              }
            }
          }
        }
      }
      .content_bottom{
        width: 100%;
        background: #f9f9f9;
        padding: 38px;
        box-sizing: border-box;
        border: 1px solid #e5e5e5;
        border-top: none;
        border-bottom-left-radius: 5px;
        border-bottom-right-radius: 5px;
        display: flex;
        flex-direction: row;
        .cb_left{
          display: flex;
          flex-direction: row;
          width: 64%;
          .cbl_one{
            width: 48%;
            background-color: #fff;
            text-align: center;
            position: relative;
            margin-right: 15px;
            display: flex;
            flex-direction: column;
            margin-top: auto;
            margin-bottom: auto;
            .cblCon_top{
              border: 1px solid #0f8ed7;
              border-top-left-radius: 3px;
              border-top-right-radius: 3px;
              border-bottom: none;
              background: #fff;
              padding: 13px;
              box-sizing: border-box;
              display: flex;
              flex-direction: column;
              .cbt_title{
                color: #666666;
                font-size: 20px;
                text-align: left;
                margin-bottom: 18px;
                position: relative;
              }
              .status{
                color: #999999;
                font-size: 14px;
                margin-bottom: 5px;
              }
              .downStatus{
                font-weight: 500;
                font-size: 24px;
                margin-bottom: 10px;
              }
              .cl{
                color: #3384dd!important;
              }
              .error{
                color: #ef4a4e!important;
              }
              .cg{
                color: #4eb240!important;
              }
              .wait{
                color: #999999!important;
              }
              .time{
                font-size: 14px;
                color: #999999;
              }
            }
            .cblCon_bottom{
              background: #fafafa;
              height: 50px;
              border: 1px solid #0f8ed7;
              border-top-color: #eeeeee;
              border-bottom-left-radius: 3px;
              border-bottom-right-radius: 3px;
              display: flex;
              flex-direction: row;
              .cblb_con{
                width: 100%;
                height: 50px;
                line-height: 50px;
                position: relative;
                font-size: 16px;
                color: #3384dd;
              }
            }
            .cb1{
              background: #fff;
              border-top: none;
            }
          }
          #cb1:after{
            content: '';
            width: 20px;
            height: 2px;
            position: absolute;
            top: 50%;
            right: -20px;
            background-color: #0f8ed7;
          }
          #cb2{
            cursor: pointer;
          }
          #cb2:after{
            content: '';
            height: 2px;
            position: absolute;
            top: 50%;
            width: 20px;
            background-color: #d5d5d5;
            right: -20px;
          }
          #cb2:before{
            content: '';
            position: absolute;
            width: 2.7rem;
            height: 209px;
            top: -4px;
            right: -65px;
            border: 2px solid #d5d5d5;
            border-right: none;
          }
        }
        .cb_right{
          display: flex;
          flex-direction: column;
          width: 32%;
          .cbl_two{
            width: 90%;
            background-color: #fff;
            text-align: center;
            position: relative;
            margin-left: auto;
            display: flex;
            flex-direction: column;
            .cblCon_top{
              border: 1px solid #0f8ed7;
              border-top-left-radius: 3px;
              border-top-right-radius: 3px;
              border-bottom: none;
              background: #fff;
              padding: 24px;
              box-sizing: border-box;
              display: flex;
              flex-direction: column;
              .cbt_title{
                color: #666666;
                font-size: 20px;
                text-align: left;
                margin-bottom: 18px;
              }
              .status{
                color: #999999;
                font-size: 14px;
                margin-bottom: 5px;
              }
              .downStatus{
                font-weight: 500;
                font-size: 24px;
                margin-bottom: 10px;
              }
              .cl{
                color: #3384dd!important;
              }
              .error{
                color: #ef4a4e!important;
              }
              .cg{
                color: #4eb240!important;
              }
              .wait{
                color: #999999!important;
              }
              .time{
                font-size: 14px;
                color: #999999;
                text-align: left;
              }
            }
            .cblCon_bottom{
              background: #fafafa;
              height: 50px;
              border: 1px solid #0f8ed7;
              border-top-color: #eeeeee;
              border-bottom-left-radius: 3px;
              border-bottom-right-radius: 3px;
              display: flex;
              flex-direction: row;
              .cblb_con{
                width: 50%;
                height: 50px;
                line-height: 50px;
                position: relative;
                font-size: 16px;
                color: #3384dd;
                cursor: pointer;
              }
              .cblb_con:after{
                content: '';
                display: block;
                position: absolute;
                right: -1px;
                top: 14px;
                width: 1px;
                height: 22px;
                background: #dcdddf;
              }
              .cblb_con:nth-child(2):after{
                display: none;
              }
            }
            .cb1{
              background: #fff;
              border-top: none;
            }
          }
          .cbl_two:first-child{
            margin-bottom: 12px;
          }
        }
      }
    }
  }
</style>
